package news.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import news.dao.AuthorDao;
import news.dao.BaseDao;
import news.entity.Author;

public class AuthorDaoImpl implements AuthorDao {

	private Connection connection;
	private PreparedStatement pstmt;
	private ResultSet rs;
	@Override
	public List<Author> findAllAuthor() {
		List<Author> auList = new ArrayList<Author>();
		try {
			connection = BaseDao.getConnection();
			String sql = "select author_id,author_no,author_name from author";
			pstmt = connection.prepareStatement(sql);
			rs = pstmt.executeQuery();
			while(rs.next()){ 
				Author a = new Author(rs.getInt("author_id"),
						rs.getString("author_no"),
						rs.getString("author_name"));
				auList.add(a);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			BaseDao.closeAll(rs, pstmt, connection);
		}
		return auList;
	}

}
